package algorithm.leetcode.I1to100;

public class Q28 {

    public int strStr(String haystack, String needle) {
        if (needle.equals("")) return 0;

        for (int i = 0; i <= haystack.length()-needle.length(); i++) {
            int index = 0, fakePos = i;
            while (index < needle.length() && haystack.charAt(fakePos) == needle.charAt(index)) {
                fakePos++; index++;
            }
            if (fakePos == i+index && index == needle.length()) return i;
        }
        return -1;
    }

    public static void main(String[] args) {
        Q28 q28 = new Q28();
        System.out.println(q28.strStr("l,", "l"));
    }

}
